﻿using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using System.Collections.Generic;
using DG.Tweening;

namespace ScreenMgr {

    /// <summary>
    /// 一个简单的类来演示自定义补间屏幕
    /// </summary>
    public class TweenedScreen : BaseScreen {
        
        public override void OnAnimationIn() {
            canvasGroup.alpha = 1f;

            Transform[] allChildren = GetComponentsInChildren<RectTransform>();

            foreach (var item in allChildren) {
                if (item.transform == this.transform) continue;
                item.localScale = new Vector3(0f, 0f, 0f);
                item.transform.DOScale(Vector3.one, Random.Range(0.2f,0.7f)).SetDelay(Random.Range(0f, 0.6f)).SetEase(Ease.OutBack);
            }
            DOVirtual.DelayedCall(0.5f, OnAnimationInEnd);
        }

        public override void OnAnimationOut() {

            canvasGroup.DOFade(0f, 0.5f).SetEase(Ease.OutCubic).OnComplete(OnAnimationOutEnd);
        }
    }

}